/*
 * @lc app=leetcode.cn id=242 lang=javascript
 *
 * [242] 有效的字母异位词
 */

// @lc code=start
/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isAnagram = function (s, t) {
  let map = new Map()

  for (let k of s) {
    if (map.get(k)) {
      map.set(k, map.get(k) + 1)
    } else {
      map.set(k, 1)
    }
  }

  for (let k of t) {
    if (map.get(k)) {
      map.set(k, map.get(k) - 1)
    } else {
      return false
    }
  }

  for (let k of map.values()) {
    if (k !== 0) {
      return false
    }
  }
  return true
}
// @lc code=end
